version 14.1
set more off

***************************************************************************************************
*THIS FILE PRODUCES TABLE A.VII OF SLEMROD-REHMAN-WASEEM-2020, RESTAT
***************************************************************************************************

/* PRELIMINARIES */

use				"$project_data\ITRM_Dislo_Unique_IncMPs_Light.dta", clear
keep				if whst==0
g 					double filedt=dofc(return_filing_date) 
format			filedt %td
drop				if year<2012 & filedt>d(01jan2013) & filedt<.
keep				regno year treat we whst logtaxpaid namefreq 
keep				if treat==1
drop				treat
#d					;
matrix 			input table=(0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0);
#d				cr

/* COMPLETE PANEL (2006-2015) */

g				after=year>=2012
local			j=1
forvalues	n=10(10)40 {
preserve
drop			if namefreq>`n' & namefreq<=40
cap			drop treat treat_*
g				treat=(namefreq<=`n')
g				treat_after=treat*after
qui			areg logtaxpaid i.year treat_after, absorb(regno) cluster(regno)
local			i=1
matrix		table[`i',`j']=_b[treat_after]
matrix 		table[`i'+1,`j']=_se[treat_after]
matrix		table[`i'+2,`j']=e(N)
local			j=`j'+2
restore
}

/* BALANCED PANEL (2006-2015) */

bys			regno:g nreturns=_N
keep			if nreturns==10
local			j=2
forvalues	n=10(10)40 {
preserve
drop			if namefreq>`n' & namefreq<=40
cap			drop treat treat_*
g				treat=(namefreq<=`n')
g				treat_after=treat*after
qui			areg logtaxpaid i.year treat_after, absorb(regno) cluster(regno)
local			i=1
matrix		table[`i',`j']=_b[treat_after]
matrix 		table[`i'+1,`j']=_se[treat_after]
matrix		table[`i'+2,`j']=e(N)
local			j=`j'+2
restore
}

/* COMPLETE PANEL (2006-2011) */

use			"$project_data\ITRM_Dislo_Unique_IncMPs_Light.dta", clear
keep			if whst==0
g 				double filedt=dofc(return_filing_date) 
format		filedt %td
drop			if year<2012 & filedt>d(01jan2013) & filedt<.
keep			regno year treat we whst logtaxpaid namefreq 
keep			if treat==1
drop			treat
drop			if year>=2012
g				after=year>=2010
local			j=1
forvalues	n=10(10)40 {
preserve
drop			if namefreq>`n' & namefreq<=40
cap			drop treat treat_*
g				treat=(namefreq<=`n')
g				treat_after=treat*after
qui			areg logtaxpaid i.year treat_after, absorb(regno) cluster(regno)
local			i=4
matrix		table[`i',`j']=_b[treat_after]
matrix 		table[`i'+1,`j']=_se[treat_after]
matrix		table[`i'+2,`j']=e(N)
local			j=`j'+2
restore
}

/* BALANCED PANEL (2006-2015) */

bys			regno:g nreturns=_N
keep			if nreturns==6
local			j=2
forvalues	n=10(10)40 {
preserve
drop			if namefreq>`n' & namefreq<=40
cap			drop treat treat_*
g				treat=(namefreq<=`n')
g				treat_after=treat*after
qui			areg logtaxpaid i.year treat_after, absorb(regno) cluster(regno)
local			i=4
matrix		table[`i',`j']=_b[treat_after]
matrix 		table[`i'+1,`j']=_se[treat_after]
matrix		table[`i'+2,`j']=e(N)
local			j=`j'+2
restore
}

/* FORMATTING THE TABLE */ 

svmat 		table
keep			tab*
drop			table9-table12
keep			if _n<=6
g				c11=""
replace		c11="treat $\times$ after" in 1
replace		c11="Observations" in 3
replace		c11="treat $\times$ after" in 4
replace		c11="Observations" in 6

forvalues 	c=1/8 {
g				c`c'=string(table`c',"%9.3f")
}
foreach		r in 2 5 {
forvalues	c=1/8 {
replace		c`c'="("+string(table`c',"%9.3f")+")" in `r'
}
}
forvalues	c=1/8 {
replace		c`c'=string(table`c',"%15.0fc") in 3
replace		c`c'=string(table`c',"%15.0fc") in 6
}
forvalues	s=1/15 {
g				s`s'="&"
}
g				l="\\"
foreach		r in 2 3 5 6 {
replace		l="\\\\" in `r'
}
order				c11 s1 c1 s2 c2 s3 s4 c3 s5 c4 s6 s7 c5 s8 c6 s9 s10 c7 s11 c8 s12 l
browse			c11 s1 c1 s2 c2 s3 s4 c3 s5 c4 s6 s7 c5 s8 c6 s9 s10 c7 s11 c8 s12 l
